package com.itheima.health.task;

import com.itheima.health.common.RedisConst;
import com.itheima.health.service.MemberService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * @author ：leaflei
 * @date ：Created in 2022年08月06日
 * @version: 1.0
 * @description ：定时查询会员饼状图数据
 */
@Slf4j
@Component
public class MemberReportTask {

    @Autowired
    private RedisTemplate redisTemplate;

    @Autowired
    private MemberService memberService;


    @Scheduled(cron = "0/60 * * * * ? ")
    public void getMemberReport(){
        log.info("=======开启定时查询会员饼状图数据=======");
        //查询会员饼状图数据
        Map<String, Object> memberReport = memberService.getMemberReport();
        //把查询的会员饼状图放到Redis中
        redisTemplate.opsForValue().set(RedisConst.MEMBER_REPORT,memberReport);

    }
}
